<h1 class="title-h1">业务员提成管理</h1>
<div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">时间范围</label>
            <div class="layui-input-inline">
                <input type="text" name="date" id="date" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="search" id="search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
            </button>
        </div>
    </div>
</div>

<div class="layui-card-body">
    <table class="layui-table" id="dataTable" lay-filter="dataTable">
    </table>

    <script type="text/html" id="expressTpl">
        {{d.username ||''}}
    </script>
    <script type="text/html" id="totalTpl">
        ￥{{d.total ||0}}
    </script>
    <script type="text/html" id="picTpl">
        <img src="{{d.qrcode}}" alt="">
    </script>
</div>
<style>
    .layui-table-tips-main {
        max-height: 500px;
    }
</style>
<script>
    layui.use(['table', 'http', 'form', 'laydate'], function () {
        var table = layui.table,
            layer = layui.layer,
            http = layui.http,
            $ = layui.$;
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date',
            range: '~',
            type: 'month',
            done: function (value, date, endDate) {
                setTimeout(() => {
                    $("#search").click()
                }, 100);
            }
        });

        form.on('submit(search)', function (data) {
            reloadTable(data.field)
            return false;
        });

        table.render({
            elem: '#dataTable',
            url: '/finance/csmanager/',
            toolbar: '#dataTableToolbar',
            page: true,
            limit: 20,
            limits: [20, 50, 100, 500],
            cols: [
                [{
                    field: 'ct',
                    title: '时间',
                    sort: true
                }, {
                    field: 'username',
                    title: '姓名',
                }, {
                    templet: '#picTpl',
                    title: '专属二维码',
                    width:120
                }, {
                    templet: '#totalTpl',
                    field: 'total',
                    title: '提成金额',
                    sort: true
                }]
            ],
            parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.count,
                    "data": res.data.data
                };
            }
        });

        var reloadTable = function (where, sort) {
            table.reload("dataTable", {
                initSort: sort,
                where: where,
            });
        }

        table.on('sort(dataTable)', function (obj) {
            reloadTable({
                field: obj.field,
                order: obj.type
            }, obj)
        });
    });
</script>